
import java.applet.AudioClip;
import java.net.URL;

/* Permet de constituer une bibliotheque de sons et de les gerer */
public class AudioLabi
{

/* ATTRIBUTS */
    public SoundList bibliSonore;
    public AudioClip clip;
    public URL dir;
    public static final String[] sounds = {
        "hitwall.wav",
        "probewall.wav",
        "fffuit.wav",
        "tada.wav",
        "bienvenue.wav",
        "instructions.wav",
        "avous.wav",
        "droite.wav",
        "gauche.wav",
        "demitour.wav",
        "toudroit.wav",
        "nord.wav",
        "sud.wav",
        "est.wav",
        "ouest.wav",
        "avancer.wav",
        "visited.wav",
        "pludaide.wav",
        "niveaudifficulte.wav",
        "apropos.wav",
        "retour.wav",
        "commandes.wav",
        "tutorial.wav",
        "comment_detecter_murs.wav",
        "instructionsPlusCourtes.wav",
        "bienvenuePlusCourt.wav",
        "aide.wav"};

/* CONSTRUCTEUR */
    public AudioLabi() throws Exception
    {
        /* Permet d'acceder aux sons quelques soit l'ordinateur */
        /*dir = new URL("file:" + System.getProperty("user.dir") + "../ressources/sons/");*/
		
        dir = new URL("file:" + StaticFields.ressourcePath + "sons/");

        /* On charge la bibliotheque sonore */
        bibliSonore = new SoundList(dir);
        for(int i=0;i<sounds.length;i++)
        {
           bibliSonore.startLoading(sounds[i]);
        }
    }

/* METHODES */

    /* Si le joueur rencontre un mur */
    public void hitWall(){
        playSound(sounds[0]);
    }

    /* Permet de determiner la presence de murs */
    public void probeWall(int isWall){
        if (isWall == 0)
          playSound(sounds[1]);
        else if (isWall == 1)
          playSound(sounds[2]);
        else
          playSound(sounds[16]);
    }

    public void win()
    {
      stop();
      playSound(sounds[3]);
    }

    public void bienvenue(){
      stop();
      playSound(sounds[4]);
    }

    public void instructions()
    {
      stop();
      playSound(sounds[5]);
    }

    public void avous()
    {
      stop();
      playSound(sounds[6]);
    }

    public void droite()
    {
      stop();
      playSound(sounds[7]);
    }

    public void gauche()
    {
      stop();
      playSound(sounds[8]);
    }

    public void uturn()
    {
       stop();
       playSound(sounds[9]);
    }

    public void droit()
    {
       stop();
       playSound(sounds[10]);
    }

    public void direction(int dir)
    {
        switch(dir)
        {
        case 0 : playSound(sounds[11]);break;
        case 1 : playSound(sounds[13]);break;
        case 2 : playSound(sounds[12]);break;
        case 3 : playSound(sounds[14]);break;
        }
    }

    public void pas()
    {
      stop();
      playSound(sounds[15]);
    }

    public void pludAide()
    {
       stop();
       playSound(sounds[17]);
    }

    public void fenChoix()
    {
      stop();
      playSound(sounds[18]);
    }


    public void apropos()
    {
      stop();
      playSound(sounds[19]);
    }

    public void retour()
    {
      stop();
      playSound(sounds[20]);
    }

    public void commandes()
   {
     stop();
     playSound(sounds[21]);
   }

   public void tutorial()
   {
     stop();
     playSound(sounds[22]);
   }

   public void comment_detecter_murs()
   {
     stop();
     playSound(sounds[23]);
   }

   public void instructionsPlusCourtes()
   {
     stop();
     playSound(sounds[24]);
   }

   public void bienvenuePlusCourt()
   {
     stop();
     playSound(sounds[25]);
   }

   public void aide()
   {
     stop();
     playSound(sounds[26]);
   }


   public void stop()
   {
       Object tabAudio [] = bibliSonore.values().toArray();
       for(int i=0; i<tabAudio.length;i++)
       {
         ((AudioClip)tabAudio[i]).stop();
       }
   }

   public void playSound(String titre)
   {
     bibliSonore.getClip(titre).play();
   }



 }
